function max(num){
    let res = num[0], sum = 0
    for(let item of num){
        if(sum<=0){
            sum = item
        }else {
            sum += item
        }
        res = Math.max(res, sum)
    }
    return res;
}

const nums = [-2, 3, -1, 1, -3]
console.log(max(nums));
